﻿
var _LoginUrl = "";
if (document.domain.indexOf('gaitu.cn') >= 0) {
    document.domain = "gaitu.cn";
    _LoginUrl = "http://login.gaitu.cn/";
}
else {
    document.domain = "gaitu.com";
    _LoginUrl = "http://login.gaitu.com/";
}
var _QQLoginUrl =     _LoginUrl+"app/qq/LoginToQQ.aspx";
var _AliPayLoginUrl = _LoginUrl+"app/alipay/Logintoali.aspx";
var _WeiBoLoginUrl =  _LoginUrl+"app/weibo/logintoweibo.aspx";
var _BindUrl =        _LoginUrl+"app/bind.aspx";
function openQQ() {
    var A = window.open(_QQLoginUrl, "TencentLogin", "width=510,height=400,menubar=0,scrollbars=0, status=1,titlebar=0,toolbar=0,location=1");
}
function openAliPay() {
    var A = window.open(_AliPayLoginUrl, "AliPayLogin", "width=960,height=600,menubar=0,scrollbars=0, titlebar=0,toolbar=0,location=1");
}

function openWeiBo() {
    var A = window.open(_WeiBoLoginUrl, "WeiBoLogin", "width=640,height=450,menubar=0,scrollbars=0, status=1,titlebar=0,toolbar=0,location=1");
}


function closeappLogin(bindstat, logid,openid) {
    //expressLoginDialog.close_dialog();
    //登陆失败
    if (bindstat == 0) {
        //express_login();
    }
    //第一次绑定
    else if (bindstat == 1) {
        show_appbind_dialog(openid,logid);
    }
    //登陆成功
    else if (bindstat == 2) {
        //getLogedJson();
        
        if ($("#hid_loginRefurl").length == 1) {
            if ($("#hid_loginRefurl").val().length < 10) {
                location.href = $("#hid_loginRefurl").val();
                return;
            }
        }
        LoginRegAfter();
    }
}

function show_appbind_dialog(openid, otherparam) {
    LoginRemove();
    var url = _BindUrl + '?openid=' + openid + '&callid=' + otherparam;
    var ifa='<iframe src="' + url + '" width="510" height="480" scrolling="no" allowtransparency="true" frameborder="0" id="select_img_frm" name="select_img_frm"></iframe>';
    popWin('绑定账号', ifa, 515, 500);
}


//loginbox

function express_login(func) {
    var funcname;
    if (typeof (func) == "function") {
        var funcstr = '"' + func + '"';
        var patrn = /function\s+(\w+?)\(/;
        if (typeof (eval(patrn.exec(funcstr)[1])) == "function") {
            funcname = patrn.exec(funcstr)[1];
        }
        else
        {
            funcname = "";
        }
        //if (!patrn.exec(s)) return false 
    }
    else if (typeof (func) == "undefined") {
        funcname = "";
    }
    else {
        funcname = func;
    }
    LoginShow(funcname);
}






function LoginShow(func) {
    $("#LoginBox").remove();
        var ifr = '<iframe id="iframelogin" width="100%" height="100%" frameborder="0" src="' + _LoginUrl + 'ilogin.aspx?t='+Math.random()+'&callback=' + func + '" scrolling="no"></iframe>';
        var htmlstr = '<div class="shells" id="LoginBox"><div  id="LoginBoxtit" style="height:30px; width:930px;cursor:move;"><div id="Login_CloseBtn"></div></div><div style=" height:430px;">' + ifr + '</div></div>';
        $("body").append(htmlstr);
        $("#LoginBox").css({ background: "#fff", width: "930px", border: "2px solid #d7d7d7", height: "467px", margin: "auto", position: "absolute", top: "100px", left: "200px" });
        $("#Login_CloseBtn").css({ width: "22px", height: "22px", float: "right", margin: "8px 10px 0 0", background: "url(" + _LoginUrl + "images/close1112.png) no-repeat -2px -3px", cursor:"pointer" });
        var ieset = navigator.userAgent;
        if (ieset.indexOf("MSIE 6.0") > -1)//浏览器判断 如果是IE6
        {
            document.getElementById("iframelogin").src = document.getElementById("iframelogin").src;
        }
        ShowBox("LoginBox", "LoginBoxtit", "Login_CloseBtn");
    }




    function LoginRemove() {
        //alert(0);
        $("#LoginBox").hide();
        $("#BgDiv").remove();
        $("#MsgDiv").remove();
    var objSelect = document.getElementsByTagName("select");
    for (var j = 0; j < objSelect.length; j++) {
        if (objSelect[j].getAttribute("display") == "block") {
            objSelect[j].style.display = "";
        }
    }
    //document.body.removeChild($("#LoginBox")[0]);
    //document.body.removeChild($("#BgDiv")[0]);
}

function LogOut() {
    var ordertype = $("#ordertype").val();
    $("body").append('<script type="text/javascript" src="' + _LoginUrl + 'jlog.aspx?ordertype=' + ordertype + '&type=logout&t=' + Math.random() + '"></script>');
}

function LoginRegAfter() {

    LoginRemove();
  
    LogSuccessStat();
}

function LogSuccessStat() {
    
    var ordertype = $("#ordertype").val();
    $("body").append('<script type="text/javascript" src="' + _LoginUrl + 'jlog.aspx?ordertype=' + ordertype + '&t=' + Math.random() + '"></script>');
}





function ShowBox(box_ID, boxtit_ID,closeBtn_ID) {
    var objSelect = document.getElementsByTagName("select"); //捕捉所有select标签
    for (var j = 0; j < objSelect.length; j++) {
        //设为不显示，再进行下面操作
        if (objSelect[j].style.display != "none") {
            objSelect[j].setAttribute("display", "block");
            objSelect[j].style.display = "none";
        }
    }
    var w = parseInt(document.getElementById(box_ID).style.width+40000);
    var h = parseInt(document.getElementById(box_ID).style.height);
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    var gtscrollTop = $(document).scrollTop();



    var bgObj = document.createElement("div");
    bgObj.id = "BgDiv";
    bgObj.style.width = iWidth + "px";
    bgObj.style.height = Math.max(document.body.clientHeight, iHeight) + "px";
    document.body.appendChild(bgObj);
    bgObj.style.position = "fixed";
    bgObj.style.top = "0";
    bgObj.style.left = "0";
    bgObj.style.right = "0";
    bgObj.style.bottom = "0";
    bgObj.style.backgroundColor = "#000";
    bgObj.style.filter = "alpha(opacity=40)";
    bgObj.style.opacity = "0.4";
    bgObj.style.zIndex = "100"
    if (version < 7.0) {
        bgObj.style.position = "absolute";
    }



    var msgObj = document.getElementById(box_ID);
    if (version < 7.0) {
        msgObj.style.top = (iHeight - h) / 2 + gtscrollTop + "px";
    } else {
        msgObj.style.top = (iHeight - h) / 2 + "px";
    }
    msgObj.style.left = (iWidth - w) / 2 + "px";
    msgObj.style.overflow = "hidden";
    if (version < 7.0) {
        msgObj.style.position = "absolute";
    } else {
        msgObj.style.position = "fixed";
    }
    msgObj.style.zIndex = "102";




    function resize() {
        iWidth = document.documentElement.clientWidth;
        iHeight = document.documentElement.clientHeight;
        var left = (iWidth - w) / 2;
        var top = (iHeight - h) / 2;
        msgObj.style.left = left + 'px';
        msgObj.style.top = top + 'px';
        bgObj.style.width = iWidth + 'px';
        bgObj.style.height = iHeight + 'px';
    }
    window.onresize = resize;

    titleBar = document.getElementById(boxtit_ID);

    var moveX = 0;
    var moveY = 0;
    var moveTop = 0;
    var moveLeft = 0;
    var moveable = false;
    var docMouseMoveEvent = document.onmousemove;
    var docMouseUpEvent = document.onmouseup;
    titleBar.onmousedown = function () {
        var evt = getEvent();
        moveable = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(msgObj.style.top);
        moveLeft = parseInt(msgObj.style.left);
        document.onmousemove = function () {
            if (moveable) {
                var evt = getEvent();
                var x = moveLeft + evt.clientX - moveX;
                var y = moveTop + evt.clientY - moveY;
                if (x > 0 && (x + w < iWidth) && y > 0 && (y + h < iHeight)) {
                    msgObj.style.left = x + "px";
                    msgObj.style.top = y + "px";
                }
            }
        };

        document.onmouseup = function () {
            if (moveable) {
                document.onmousemove = docMouseMoveEvent;
                document.onmouseup = docMouseUpEvent;
                moveable = false;
                moveX = 0;
                moveY = 0;
                moveTop = 0;
                moveLeft = 0;
            }
        };
    }

    var closeBtn = document.getElementById(closeBtn_ID);
    closeBtn.onclick = function () {
        for (var j = 0; j < objSelect.length; j++) {
            //再给select显出来
            if (objSelect[j].getAttribute("display") == "block") {
                objSelect[j].style.display = "";
            }
        }
        document.body.removeChild(bgObj);
        document.body.removeChild(msgObj);
    }



    // 获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
        return window.event || arguments.callee.caller.arguments[0];
    }
}


